<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: huajie <banhuajie@163.com>
// +----------------------------------------------------------------------
namespace Admin\Controller;
/**
 * 洗涤小助手-清洁难题 控制器
 * @author 咩咩 <liuyangvsms@163.com>
 */
class CleanController extends AdminController {

    /**
     * 清洁难题-总览
     */
    public function index(){
        /*--------------------------测试开始--------------------------*/
//        $name = '名字';
//        error_log('name='.$name."\n", 3, "test.log");//打印日志



        /*--------------------------测试结束--------------------------*/

        $this->meta_title = '清洁难题-总览';//页面title信息
        $this->assign('title', '清洁难题-总览');//页面标题
        $this->display();
    }

    /**
     * 轮播图管理-轮播图
     */
    public function lunbo(){
        $db_wash_clean_lunbo = M('wash_clean_lunbo');//实例化轮播表

        $wash_clean_lunbo = $db_wash_clean_lunbo->order('id DESC')->field('id,img_url,title')->select();
        $arr = $wash_clean_lunbo;

        /* 数组分页 */
        import("ORG.Util.Page"); //导入分页类
        $count = count($arr);//获取数组长度
        $Page = new \Think\Page($count, 10);//设置每页显示条数
        $Page->rollPage = 5;//中间显示页数(如果不配置将隐藏首尾页)
        $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        $show = $Page->show();// 分页显示输出
        $list = array_slice($arr, $Page->firstRow, $Page->listRows);
        $this->assign('list', $list);// 赋值数据集
        $this->assign('page', $show);// 赋值分页输出

        $this->meta_title = '轮播图管理-轮播图';//页面title信息
        $this->assign('title', '轮播图管理-轮播图');//页面标题
        $this->display();
    }

    /**
     * 轮播图管理-轮播图-新增
     */
    public function lunbo_add(){
        $db_wash_clean_lunbo = M('wash_clean_lunbo');//实例化轮播表

        if(IS_POST){
            $title = I('post.title');
            $type = I('post.type');
            $url = I('post.url');
            $local_url = I('post.local_url');
            $content = I('post.content');

            /*文件上传*/
            $savename = time().'_'.mt_rand(1000000,9999999);
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize = 2048000;// 设置附件上传大小 2M=2048000
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
            $upload->savePath = './Clean/lunbo/picture/'; // 设置附件上传（子）目录
            $upload->saveName = $savename; // 上传文件的文件名
            //$upload->saveExt = 'jpg'; // 上传文件的保存后缀，不设置的话使用原文件后缀
            $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
            $upload->replace = true; // true会存在同名文件将覆盖
            // 上传文件
            $upload_info = $upload->upload();
            if (!$upload_info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }else{
                $img_url = "/wash_helper/Uploads/Clean/lunbo/picture/".$upload_info['file']['savename'];
                $info['img_url'] = $img_url;

                $info['title'] = $title;
                $info['type'] = $type;
                $info['url'] = $url;
                $info['local_url'] = $local_url;
                $info['content'] = $content;
                $add_wash_clean_lunbo = $db_wash_clean_lunbo->data($info)->add();
                if($add_wash_clean_lunbo){
                    $this->redirect('Clean/lunbo');
                }else{
                    $this->error('保存失败!');
                }
            }
        }

        $this->meta_title = '轮播图管理-轮播图-新增';//页面title信息
        $this->assign('title', '轮播图管理-轮播图-新增');//页面标题
        $this->display();
    }

    /**
     * 轮播图管理-轮播图-编辑
     */
    public function lunbo_edit(){
        $db_wash_clean_lunbo = M('wash_clean_lunbo');//实例化轮播表

        $id = I('get.id');//轮播图ID
        $lunbo = $db_wash_clean_lunbo->where("id='$id'")->find();
        $this->assign('lunbo', $lunbo);

        if(IS_POST){
            $title = I('post.title');
            $type = I('post.type');
            $url = I('post.url');
            $local_url = I('post.local_url');
            $content = I('post.content');

            //判断是否有文件上传
            if($_FILES["file"]["tmp_name"]){
                /*文件上传*/
                $savename = time().'_'.mt_rand(1000000,9999999);
                $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize = 2048000;// 设置附件上传大小 2M=2048000
                $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
                $upload->savePath = './Clean/lunbo/picture/'; // 设置附件上传（子）目录
                $upload->saveName = $savename; // 上传文件的文件名
                //$upload->saveExt = 'jpg'; // 上传文件的保存后缀，不设置的话使用原文件后缀
                $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
                $upload->replace = true; // true会存在同名文件将覆盖
                // 上传文件
                $upload_info = $upload->upload();
                if (!$upload_info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{
                    $img_url = "/wash_helper/Uploads/Clean/lunbo/picture/".$upload_info['file']['savename'];
                    $info['img_url'] = $img_url;

                    /*删除文件*/
                    $img_url_path = '..'.$lunbo['img_url'];
                    if(file_exists($img_url_path)){
                        unlink($img_url_path);
                    }
                }
            }

            $info['title'] = $title;
            $info['type'] = $type;
            $info['url'] = $url;
            $info['local_url'] = $local_url;
            $info['content'] = $content;
            $edit_wash_clean_lunbo = $db_wash_clean_lunbo->where("id='$id'")->setField($info);
            if($edit_wash_clean_lunbo){
                $this->redirect('Clean/lunbo');
            }else{
                $this->error('保存失败!');
            }
        }

        $this->meta_title = '轮播图管理-轮播图-编辑';//页面title信息
        $this->assign('title', '轮播图管理-轮播图-编辑');//页面标题
        $this->display();
    }

    /**
     * 轮播图管理-轮播图-删除
     */
    public function lunbo_del(){
        $db_wash_clean_lunbo = M('wash_clean_lunbo');//实例化轮播表

        $id = I('get.id');//轮播图ID
        $lunbo = $db_wash_clean_lunbo->where("id='$id'")->find();

        /*删除文件*/
        $img_url_path = '..'.$lunbo['img_url'];
        if(file_exists($img_url_path)){
            unlink($img_url_path);
        }

        /*删除静态页面图片*/
        $this->del_images_path($lunbo['content'],2);

        $del_wash_clean_lunbo = $db_wash_clean_lunbo->where("id='$id'")->delete();
        if($del_wash_clean_lunbo){
            $this->success('删除成功!');
        }else{
            $this->error('删除失败!');
        }
    }

    /**
     * 轮播图管理-轮播图-详情
     */
    public function lunbo_detail(){
        $db_wash_clean_lunbo = M('wash_clean_lunbo');//实例化轮播表

        $id = I('get.id');//轮播图ID
        $lunbo = $db_wash_clean_lunbo->where("id='$id'")->find();
        $this->assign('lunbo', $lunbo);

        $this->meta_title = '轮播图管理-轮播图-详情';//页面title信息
        $this->assign('title', '轮播图管理-轮播图-详情');//页面标题
        $this->display();
    }

    /**
     * 衣物清洁-图文
     */
    public function clothes_word(){
        $db_wash_clean_clothes = M('wash_clean_clothes');//实例化衣物清洁信息表

        $type = 1;//1图文 2视频
        $wash_clean_clothes = $db_wash_clean_clothes->where("type='$type'")->order('top DESC,search_times DESC,id DESC')->field('id,title,banner_img_url,search_times,datetime,top')->select();
        $arr = $wash_clean_clothes;

        /* 数组分页 */
        import("ORG.Util.Page"); //导入分页类
        $count = count($arr);//获取数组长度
        $Page = new \Think\Page($count, 10);//设置每页显示条数
        $Page->rollPage = 5;//中间显示页数(如果不配置将隐藏首尾页)
        $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        $show = $Page->show();// 分页显示输出
        $list = array_slice($arr, $Page->firstRow, $Page->listRows);
        $this->assign('list', $list);// 赋值数据集
        $this->assign('page', $show);// 赋值分页输出

        $this->meta_title = '衣物清洁-图文';//页面title信息
        $this->assign('title', '衣物清洁-图文');//页面标题
        $this->display();
    }

    /**
     * 衣物清洁-图文-新增
     */
    public function clothes_word_add(){
        $db_wash_clean_clothes = M('wash_clean_clothes');//实例化衣物清洁信息表

        if(IS_POST){
            $title = I('post.title');
            $content = I('post.content');
            $top = I('post.top');

            /*文件上传*/
            $savename = time().'_'.mt_rand(1000000,9999999);
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize = 2048000;// 设置附件上传大小 2M=2048000
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
            $upload->savePath = './Clean/clothes_word/picture/'; // 设置附件上传（子）目录
            $upload->saveName = $savename; // 上传文件的文件名
            //$upload->saveExt = 'jpg'; // 上传文件的保存后缀，不设置的话使用原文件后缀
            $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
            $upload->replace = true; // true会存在同名文件将覆盖
            // 上传文件
            $upload_info = $upload->upload();
            if (!$upload_info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }else{
                $banner_img_url = "/wash_helper/Uploads/Clean/clothes_word/picture/".$upload_info['file']['savename'];
                $info['banner_img_url'] = $banner_img_url;

                $info['title'] = $title;
                $info['content'] = $content;
                $info['top'] = $top;
                $info['type'] = 1; //1图文 2视频
                $info['search_times'] = 0; //搜索次数

                /*生成cid*/
                $cid = create_cid('wash_clean_clothes');
                $info['cid'] = $cid;

                /*更新时间*/
                $info['datetime'] = date('Y-m-d H:i:s');
                $info['time'] = time();

                $add_wash_clean_clothes_word = $db_wash_clean_clothes->data($info)->add();
                if($add_wash_clean_clothes_word){
                    $this->redirect('Clean/clothes_word');
                }else{
                    $this->error('保存失败!');
                }
            }
        }

        $this->meta_title = '衣物清洁-图文-新增';//页面title信息
        $this->assign('title', '衣物清洁-图文-新增');//页面标题
        $this->display();
    }

    /**
     * 衣物清洁-图文-编辑
     */
    public function clothes_word_edit(){
        $db_wash_clean_clothes = M('wash_clean_clothes');//实例化衣物清洁信息表

        $id = I('get.id');
        $clothes_word = $db_wash_clean_clothes->where("id='$id'")->find();
        $this->assign('clothes_word', $clothes_word);

        if(IS_POST){
            $title = I('post.title');
            $content = I('post.content');
            $top = I('post.top');

            //判断是否有文件上传
            if($_FILES["file"]["tmp_name"]){
                /*文件上传*/
                $savename = time().'_'.mt_rand(1000000,9999999);
                $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize = 2048000;// 设置附件上传大小 2M=2048000
                $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
                $upload->savePath = './Clean/clothes_word/picture/'; // 设置附件上传（子）目录
                $upload->saveName = $savename; // 上传文件的文件名
                //$upload->saveExt = 'jpg'; // 上传文件的保存后缀，不设置的话使用原文件后缀
                $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
                $upload->replace = true; // true会存在同名文件将覆盖
                // 上传文件
                $upload_info = $upload->upload();
                if (!$upload_info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{
                    $banner_img_url = "/wash_helper/Uploads/Clean/clothes_word/picture/".$upload_info['file']['savename'];
                    $info['banner_img_url'] = $banner_img_url;

                    /*删除文件*/
                    $banner_img_url_path = '..'.$clothes_word['banner_img_url'];
                    if(file_exists($banner_img_url_path)){
                        unlink($banner_img_url_path);
                    }
                }
            }

            $info['title'] = $title;
            $info['content'] = $content;
            $info['top'] = $top;

            /*更新时间*/
            $info['datetime'] = date('Y-m-d H:i:s');
            $info['time'] = time();

            $edit_wash_clean_clothes_word = $db_wash_clean_clothes->where("id='$id'")->setField($info);
            if($edit_wash_clean_clothes_word){
                $this->redirect('Clean/clothes_word');
            }else{
                $this->error('保存失败!');
            }
        }

        $this->meta_title = '衣物清洁-图文-编辑';//页面title信息
        $this->assign('title', '衣物清洁-图文-编辑');//页面标题
        $this->display();
    }

    /**
     * 衣物清洁-图文-删除
     */
    public function clothes_word_del(){
        $db_wash_clean_clothes = M('wash_clean_clothes');//实例化衣物清洁信息表

        $id = I('get.id');
        $clothes_word = $db_wash_clean_clothes->where("id='$id'")->find();

        /*删除文件*/
        $banner_img_url_path = '..'.$clothes_word['banner_img_url'];
        if(file_exists($banner_img_url_path)){
            unlink($banner_img_url_path);
        }

        /*删除图文混排图片*/
        $this->del_images_path($clothes_word['content'],2);

        $del_wash_clean_clothes_word = $db_wash_clean_clothes->where("id='$id'")->delete();
        if($del_wash_clean_clothes_word){
            $this->success('删除成功!');
        }else{
            $this->error('删除失败!');
        }
    }

    /**
     * 衣物清洁-图文-详情
     */
    public function clothes_word_detail(){
        $db_wash_clean_clothes = M('wash_clean_clothes');//实例化衣物清洁信息表

        $id = I('get.id');
        $clothes_word = $db_wash_clean_clothes->where("id='$id'")->find();
        $this->assign('clothes_word', $clothes_word);

        $this->meta_title = '衣物清洁-图文-详情';//页面title信息
        $this->assign('title', '衣物清洁-图文-详情');//页面标题
        $this->display();
    }

    /**
     * 衣物清洁-视频
     */
    public function clothes_video(){
        $db_wash_clean_clothes = M('wash_clean_clothes');//实例化衣物清洁信息表

        $type = 2;//1图文 2视频
        $wash_clean_clothes = $db_wash_clean_clothes->where("type='$type'")->order('top DESC,search_times DESC,id DESC')->field('id,title,banner_img_url,video_url,search_times,datetime,top')->select();
        $arr = $wash_clean_clothes;

        /* 数组分页 */
        import("ORG.Util.Page"); //导入分页类
        $count = count($arr);//获取数组长度
        $Page = new \Think\Page($count, 10);//设置每页显示条数
        $Page->rollPage = 5;//中间显示页数(如果不配置将隐藏首尾页)
        $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        $show = $Page->show();// 分页显示输出
        $list = array_slice($arr, $Page->firstRow, $Page->listRows);
        $this->assign('list', $list);// 赋值数据集
        $this->assign('page', $show);// 赋值分页输出

        $this->meta_title = '衣物清洁-视频';//页面title信息
        $this->assign('title', '衣物清洁-视频');//页面标题
        $this->display();
    }

    /**
     * 衣物清洁-视频-新增
     */
    public function clothes_video_add(){
        $db_wash_clean_clothes = M('wash_clean_clothes');//实例化衣物清洁信息表

        if(IS_POST){
            $title = I('post.title');
            $content = I('post.content');
            $top = I('post.top');

            /*文件上传*/
            $videofile = array();
            $imagefile = array();
            $savename = time().'_'.mt_rand(1000000,9999999);
            $upload = new \Think\Upload();// 实例化上传类

            /*上传视频*/
            $videofile['video'] = $_FILES['video'];
            $upload->maxSize = 5120000;// 设置附件上传大小 5M=5120000
            $upload->exts = array('mp4', 'webm', 'ogg');// 设置附件上传类型
            $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
            $upload->savePath = './Clean/clothes_video/video/'; // 设置附件上传（子）目录
            $upload->saveName = $savename; // 上传文件的文件名
            //$upload->saveExt = 'mp4'; // 上传文件的保存后缀，不设置的话使用原文件后缀
            $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
            $upload->replace = true; // true会存在同名文件将覆盖
            // 上传文件
            $upload_video_info = $upload->upload($videofile);
            if (!$upload_video_info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }

            /*上传图片*/
            $imagefile['picture'] = $_FILES['picture'];
            $upload->maxSize = 2048000;// 设置附件上传大小 2M=2048000
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
            $upload->savePath = './Clean/clothes_video/picture/'; // 设置附件上传（子）目录
            $upload->saveName = $savename; // 上传文件的文件名
            //$upload->saveExt = 'jpg'; // 上传文件的保存后缀，不设置的话使用原文件后缀
            $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
            $upload->replace = true; // true会存在同名文件将覆盖
            // 上传文件
            $upload_picture_info = $upload->upload($imagefile);
            if (!$upload_picture_info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }

            $video_url = "/wash_helper/Uploads/Clean/clothes_video/video/".$upload_video_info['video']['savename'];
            $info['video_url'] = $video_url;
            $banner_img_url = "/wash_helper/Uploads/Clean/clothes_video/picture/".$upload_picture_info['picture']['savename'];
            $info['banner_img_url'] = $banner_img_url;

            $info['title'] = $title;
            $info['content'] = $content;
            $info['type'] = 2; //1图文 2视频
            $info['search_times'] = 0; //搜索次数
            $info['top'] = $top;

            /*生成cid*/
            $cid = create_cid('wash_clean_clothes');
            $info['cid'] = $cid;

            /*更新时间*/
            $info['datetime'] = date('Y-m-d H:i:s');
            $info['time'] = time();

            $add_wash_clean_clothes_video = $db_wash_clean_clothes->data($info)->add();
            if($add_wash_clean_clothes_video){
                $this->redirect('Clean/clothes_video');
            }else{
                $this->error('保存失败!');
            }
        }

        $this->meta_title = '衣物清洁-视频-新增';//页面title信息
        $this->assign('title', '衣物清洁-视频-新增');//页面标题
        $this->display();
    }

    /**
     * 衣物清洁-视频-编辑
     */
    public function clothes_video_edit(){
        $db_wash_clean_clothes = M('wash_clean_clothes');//实例化衣物清洁信息表

        $id = I('get.id');
        $clothes_video = $db_wash_clean_clothes->where("id='$id'")->find();
        $this->assign('clothes_video', $clothes_video);

        if(IS_POST){
            $title = I('post.title');
            $content = I('post.content');
            $top = I('post.top');

            //判断是否有视频上传
            if($_FILES["video"]["tmp_name"]) {
                $videofile = array();
                /*上传视频*/
                $savename = time().'_'.mt_rand(1000000,9999999);
                $upload = new \Think\Upload();// 实例化上传类

                $videofile['video'] = $_FILES['video'];
                $upload->maxSize = 5120000;// 设置附件上传大小 5M=5120000
                $upload->exts = array('mp4', 'webm', 'ogg');// 设置附件上传类型
                $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
                $upload->savePath = './Clean/clothes_video/video/'; // 设置附件上传（子）目录
                $upload->saveName = $savename; // 上传文件的文件名
                //$upload->saveExt = 'mp4'; // 上传文件的保存后缀，不设置的话使用原文件后缀
                $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
                $upload->replace = true; // true会存在同名文件将覆盖
                // 上传文件
                $upload_video_info = $upload->upload($videofile);
                if (!$upload_video_info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{
                    $video_url = "/wash_helper/Uploads/Clean/clothes_video/video/".$upload_video_info['video']['savename'];
                    $info['video_url'] = $video_url;

                    /*删除文件*/
                    $video_url_path = '..'.$clothes_video['video_url'];
                    if(file_exists($video_url_path)){
                        unlink($video_url_path);
                    }
                }
            }

            //判断是否有图片上传
            if($_FILES["picture"]["tmp_name"]) {
                $imagefile = array();
                /*上传图片*/
                $savename = time().'_'.mt_rand(1000000,9999999);
                $upload = new \Think\Upload();// 实例化上传类

                $imagefile['picture'] = $_FILES['picture'];
                $upload->maxSize = 2048000;// 设置附件上传大小 2M=2048000
                $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
                $upload->savePath = './Clean/clothes_video/picture/'; // 设置附件上传（子）目录
                $upload->saveName = $savename; // 上传文件的文件名
                //$upload->saveExt = 'jpg'; // 上传文件的保存后缀，不设置的话使用原文件后缀
                $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
                $upload->replace = true; // true会存在同名文件将覆盖
                // 上传文件
                $upload_picture_info = $upload->upload($imagefile);
                if (!$upload_picture_info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{
                    $banner_img_url = "/wash_helper/Uploads/Clean/clothes_video/picture/".$upload_picture_info['picture']['savename'];
                    $info['banner_img_url'] = $banner_img_url;

                    /*删除文件*/
                    $banner_img_url_path = '..'.$clothes_video['banner_img_url'];
                    if(file_exists($banner_img_url_path)){
                        unlink($banner_img_url_path);
                    }
                }
            }

            $info['title'] = $title;
            $info['content'] = $content;
            $info['top'] = $top;

            /*更新时间*/
            $info['datetime'] = date('Y-m-d H:i:s');
            $info['time'] = time();

            $edit_wash_clean_clothes_video = $db_wash_clean_clothes->where("id='$id'")->setField($info);
            if($edit_wash_clean_clothes_video){
                $this->redirect('Clean/clothes_video');
            }else{
                $this->error('保存失败!');
            }
        }

        $this->meta_title = '衣物清洁-视频-编辑';//页面title信息
        $this->assign('title', '衣物清洁-视频-编辑');//页面标题
        $this->display();
    }

    /**
     * 衣物清洁-视频-删除
     */
    public function clothes_video_del(){
        $db_wash_clean_clothes = M('wash_clean_clothes');//实例化衣物清洁信息表

        $id = I('get.id');
        $clothes_video = $db_wash_clean_clothes->where("id='$id'")->find();

        /*删除文件*/
        $video_url_path = '..'.$clothes_video['video_url'];
        if(file_exists($video_url_path)){
            unlink($video_url_path);
        }

        /*删除文件*/
        $banner_img_url_path = '..'.$clothes_video['banner_img_url'];
        if(file_exists($banner_img_url_path)){
            unlink($banner_img_url_path);
        }

        /*删除图文混排图片*/
        $this->del_images_path($clothes_video['content'],2);

        $del_wash_clean_clothes_video = $db_wash_clean_clothes->where("id='$id'")->delete();
        if($del_wash_clean_clothes_video){
            $this->success('删除成功!');
        }else{
            $this->error('删除失败!');
        }
    }

    /**
     * 衣物清洁-视频-详情
     */
    public function clothes_video_detail(){
        $db_wash_clean_clothes = M('wash_clean_clothes');//实例化衣物清洁信息表

        $id = I('get.id');
        $clothes_video = $db_wash_clean_clothes->where("id='$id'")->find();
        $this->assign('clothes_video', $clothes_video);

        $this->meta_title = '衣物清洁-视频-详情';//页面title信息
        $this->assign('title', '衣物清洁-视频-详情');//页面标题
        $this->display();
    }

    /**
     * 厨房清洁-图文
     */
    public function kitchen_word(){
        $db_wash_clean_kitchen = M('wash_clean_kitchen');//实例化厨房清洁信息表

        $type = 1;//1图文 2视频
        $wash_clean_kitchen = $db_wash_clean_kitchen->where("type='$type'")->order('top DESC,search_times DESC,id DESC')->field('id,title,banner_img_url,search_times,datetime,top')->select();
        $arr = $wash_clean_kitchen;

        /* 数组分页 */
        import("ORG.Util.Page"); //导入分页类
        $count = count($arr);//获取数组长度
        $Page = new \Think\Page($count, 10);//设置每页显示条数
        $Page->rollPage = 5;//中间显示页数(如果不配置将隐藏首尾页)
        $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        $show = $Page->show();// 分页显示输出
        $list = array_slice($arr, $Page->firstRow, $Page->listRows);
        $this->assign('list', $list);// 赋值数据集
        $this->assign('page', $show);// 赋值分页输出

        $this->meta_title = '厨房清洁-图文';//页面title信息
        $this->assign('title', '厨房清洁-图文');//页面标题
        $this->display();
    }

    /**
     * 厨房清洁-图文-新增
     */
    public function kitchen_word_add(){
        $db_wash_clean_kitchen = M('wash_clean_kitchen');//实例化厨房清洁信息表

        if(IS_POST){
            $title = I('post.title');
            $content = I('post.content');
            $top = I('post.top');

            /*文件上传*/
            $savename = time().'_'.mt_rand(1000000,9999999);
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize = 2048000;// 设置附件上传大小 2M=2048000
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
            $upload->savePath = './Clean/kitchen_word/picture/'; // 设置附件上传（子）目录
            $upload->saveName = $savename; // 上传文件的文件名
            //$upload->saveExt = 'jpg'; // 上传文件的保存后缀，不设置的话使用原文件后缀
            $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
            $upload->replace = true; // true会存在同名文件将覆盖
            // 上传文件
            $upload_info = $upload->upload();
            if (!$upload_info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }else{
                $banner_img_url = "/wash_helper/Uploads/Clean/kitchen_word/picture/".$upload_info['file']['savename'];
                $info['banner_img_url'] = $banner_img_url;

                $info['title'] = $title;
                $info['content'] = $content;
                $info['top'] = $top;
                $info['type'] = 1; //1图文 2视频
                $info['search_times'] = 0; //搜索次数

                /*生成cid*/
                $cid = create_cid('wash_clean_kitchen');
                $info['cid'] = $cid;

                /*更新时间*/
                $info['datetime'] = date('Y-m-d H:i:s');
                $info['time'] = time();

                $add_wash_clean_kitchen_word = $db_wash_clean_kitchen->data($info)->add();
                if($add_wash_clean_kitchen_word){
                    $this->redirect('Clean/kitchen_word');
                }else{
                    $this->error('保存失败!');
                }
            }
        }

        $this->meta_title = '厨房清洁-图文-新增';//页面title信息
        $this->assign('title', '厨房清洁-图文-新增');//页面标题
        $this->display();
    }

    /**
     * 厨房清洁-图文-编辑
     */
    public function kitchen_word_edit(){
        $db_wash_clean_kitchen = M('wash_clean_kitchen');//实例化厨房清洁信息表

        $id = I('get.id');
        $kitchen_word = $db_wash_clean_kitchen->where("id='$id'")->find();
        $this->assign('kitchen_word', $kitchen_word);

        if(IS_POST){
            $title = I('post.title');
            $content = I('post.content');
            $top = I('post.top');

            //判断是否有文件上传
            if($_FILES["file"]["tmp_name"]){
                /*文件上传*/
                $savename = time().'_'.mt_rand(1000000,9999999);
                $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize = 2048000;// 设置附件上传大小 2M=2048000
                $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
                $upload->savePath = './Clean/kitchen_word/picture/'; // 设置附件上传（子）目录
                $upload->saveName = $savename; // 上传文件的文件名
                //$upload->saveExt = 'jpg'; // 上传文件的保存后缀，不设置的话使用原文件后缀
                $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
                $upload->replace = true; // true会存在同名文件将覆盖
                // 上传文件
                $upload_info = $upload->upload();
                if (!$upload_info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{
                    $banner_img_url = "/wash_helper/Uploads/Clean/kitchen_word/picture/".$upload_info['file']['savename'];
                    $info['banner_img_url'] = $banner_img_url;

                    /*删除文件*/
                    $banner_img_url_path = '..'.$kitchen_word['banner_img_url'];
                    if(file_exists($banner_img_url_path)){
                        unlink($banner_img_url_path);
                    }
                }
            }

            $info['title'] = $title;
            $info['content'] = $content;
            $info['top'] = $top;

            /*更新时间*/
            $info['datetime'] = date('Y-m-d H:i:s');
            $info['time'] = time();

            $edit_wash_clean_kitchen_word = $db_wash_clean_kitchen->where("id='$id'")->setField($info);
            if($edit_wash_clean_kitchen_word){
                $this->redirect('Clean/kitchen_word');
            }else{
                $this->error('保存失败!');
            }
        }

        $this->meta_title = '厨房清洁-图文-编辑';//页面title信息
        $this->assign('title', '厨房清洁-图文-编辑');//页面标题
        $this->display();
    }

    /**
     * 厨房清洁-图文-删除
     */
    public function kitchen_word_del(){
        $db_wash_clean_kitchen = M('wash_clean_kitchen');//实例化厨房清洁信息表

        $id = I('get.id');
        $kitchen_word = $db_wash_clean_kitchen->where("id='$id'")->find();

        /*删除文件*/
        $banner_img_url_path = '..'.$kitchen_word['banner_img_url'];
        if(file_exists($banner_img_url_path)){
            unlink($banner_img_url_path);
        }

        /*删除图文混排图片*/
        $this->del_images_path($kitchen_word['content'],2);

        $del_wash_clean_kitchen_word = $db_wash_clean_kitchen->where("id='$id'")->delete();
        if($del_wash_clean_kitchen_word){
            $this->success('删除成功!');
        }else{
            $this->error('删除失败!');
        }
    }

    /**
     * 厨房清洁-图文-详情
     */
    public function kitchen_word_detail(){
        $db_wash_clean_kitchen = M('wash_clean_kitchen');//实例化厨房清洁信息表

        $id = I('get.id');
        $kitchen_word = $db_wash_clean_kitchen->where("id='$id'")->find();
        $this->assign('kitchen_word', $kitchen_word);

        $this->meta_title = '厨房清洁-图文-详情';//页面title信息
        $this->assign('title', '厨房清洁-图文-详情');//页面标题
        $this->display();
    }

    /**
     * 厨房清洁-视频
     */
    public function kitchen_video(){
        $db_wash_clean_kitchen = M('wash_clean_kitchen');//实例化厨房清洁信息表

        $type = 2;//1图文 2视频
        $wash_clean_kitchen_video = $db_wash_clean_kitchen->where("type='$type'")->order('top DESC,search_times DESC,id DESC')->field('id,title,banner_img_url,video_url,search_times,datetime,top')->select();
        $arr = $wash_clean_kitchen_video;

        /* 数组分页 */
        import("ORG.Util.Page"); //导入分页类
        $count = count($arr);//获取数组长度
        $Page = new \Think\Page($count, 10);//设置每页显示条数
        $Page->rollPage = 5;//中间显示页数(如果不配置将隐藏首尾页)
        $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        $show = $Page->show();// 分页显示输出
        $list = array_slice($arr, $Page->firstRow, $Page->listRows);
        $this->assign('list', $list);// 赋值数据集
        $this->assign('page', $show);// 赋值分页输出

        $this->meta_title = '厨房清洁-视频';//页面title信息
        $this->assign('title', '厨房清洁-视频');//页面标题
        $this->display();
    }

    /**
     * 厨房清洁-视频-新增
     */
    public function kitchen_video_add(){
        $db_wash_clean_kitchen = M('wash_clean_kitchen');//实例化厨房清洁信息表

        if(IS_POST){
            $title = I('post.title');
            $content = I('post.content');
            $top = I('post.top');

            /*文件上传*/
            $videofile = array();
            $imagefile = array();
            $savename = time().'_'.mt_rand(1000000,9999999);
            $upload = new \Think\Upload();// 实例化上传类

            /*上传视频*/
            $videofile['video'] = $_FILES['video'];
            $upload->maxSize = 5120000;// 设置附件上传大小 5M=5120000
            $upload->exts = array('mp4', 'webm', 'ogg');// 设置附件上传类型
            $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
            $upload->savePath = './Clean/kitchen_video/video/'; // 设置附件上传（子）目录
            $upload->saveName = $savename; // 上传文件的文件名
            //$upload->saveExt = 'mp4'; // 上传文件的保存后缀，不设置的话使用原文件后缀
            $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
            $upload->replace = true; // true会存在同名文件将覆盖
            // 上传文件
            $upload_video_info = $upload->upload($videofile);
            if (!$upload_video_info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }

            /*上传图片*/
            $imagefile['picture'] = $_FILES['picture'];
            $upload->maxSize = 2048000;// 设置附件上传大小 2M=2048000
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
            $upload->savePath = './Clean/kitchen_video/picture/'; // 设置附件上传（子）目录
            $upload->saveName = $savename; // 上传文件的文件名
            //$upload->saveExt = 'jpg'; // 上传文件的保存后缀，不设置的话使用原文件后缀
            $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
            $upload->replace = true; // true会存在同名文件将覆盖
            // 上传文件
            $upload_picture_info = $upload->upload($imagefile);
            if (!$upload_picture_info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }

            $video_url = "/wash_helper/Uploads/Clean/kitchen_video/video/".$upload_video_info['video']['savename'];
            $info['video_url'] = $video_url;
            $banner_img_url = "/wash_helper/Uploads/Clean/kitchen_video/picture/".$upload_picture_info['picture']['savename'];
            $info['banner_img_url'] = $banner_img_url;

            $info['title'] = $title;
            $info['content'] = $content;
            $info['type'] = 2; //1图文 2视频
            $info['search_times'] = 0; //搜索次数
            $info['top'] = $top;

            /*生成cid*/
            $cid = create_cid('wash_clean_kitchen');
            $info['cid'] = $cid;

            /*更新时间*/
            $info['datetime'] = date('Y-m-d H:i:s');
            $info['time'] = time();

            $add_wash_clean_kitchen_video = $db_wash_clean_kitchen->data($info)->add();
            if($add_wash_clean_kitchen_video){
                $this->redirect('Clean/kitchen_video');
            }else{
                $this->error('保存失败!');
            }
        }

        $this->meta_title = '厨房清洁-视频-新增';//页面title信息
        $this->assign('title', '厨房清洁-视频-新增');//页面标题
        $this->display();
    }

    /**
     * 厨房清洁-视频-编辑
     */
    public function kitchen_video_edit(){
        $db_wash_clean_kitchen = M('wash_clean_kitchen');//实例化厨房清洁信息表

        $id = I('get.id');
        $kitchen_video = $db_wash_clean_kitchen->where("id='$id'")->find();
        $this->assign('kitchen_video', $kitchen_video);

        if(IS_POST){
            $title = I('post.title');
            $content = I('post.content');
            $top = I('post.top');

            //判断是否有视频上传
            if($_FILES["video"]["tmp_name"]) {
                $videofile = array();
                /*上传视频*/
                $savename = time().'_'.mt_rand(1000000,9999999);
                $upload = new \Think\Upload();// 实例化上传类

                $videofile['video'] = $_FILES['video'];
                $upload->maxSize = 5120000;// 设置附件上传大小 5M=5120000
                $upload->exts = array('mp4', 'webm', 'ogg');// 设置附件上传类型
                $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
                $upload->savePath = './Clean/kitchen_video/video/'; // 设置附件上传（子）目录
                $upload->saveName = $savename; // 上传文件的文件名
                //$upload->saveExt = 'mp4'; // 上传文件的保存后缀，不设置的话使用原文件后缀
                $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
                $upload->replace = true; // true会存在同名文件将覆盖
                // 上传文件
                $upload_video_info = $upload->upload($videofile);
                if (!$upload_video_info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{
                    $video_url = "/wash_helper/Uploads/Clean/kitchen_video/video/".$upload_video_info['video']['savename'];
                    $info['video_url'] = $video_url;

                    /*删除文件*/
                    $video_url_path = '..'.$kitchen_video['video_url'];
                    if(file_exists($video_url_path)){
                        unlink($video_url_path);
                    }
                }
            }

            //判断是否有图片上传
            if($_FILES["picture"]["tmp_name"]) {
                $imagefile = array();
                /*上传图片*/
                $savename = time().'_'.mt_rand(1000000,9999999);
                $upload = new \Think\Upload();// 实例化上传类

                $imagefile['picture'] = $_FILES['picture'];
                $upload->maxSize = 2048000;// 设置附件上传大小 2M=2048000
                $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
                $upload->savePath = './Clean/kitchen_video/picture/'; // 设置附件上传（子）目录
                $upload->saveName = $savename; // 上传文件的文件名
                //$upload->saveExt = 'jpg'; // 上传文件的保存后缀，不设置的话使用原文件后缀
                $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
                $upload->replace = true; // true会存在同名文件将覆盖
                // 上传文件
                $upload_picture_info = $upload->upload($imagefile);
                if (!$upload_picture_info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{
                    $banner_img_url = "/wash_helper/Uploads/Clean/kitchen_video/picture/".$upload_picture_info['picture']['savename'];
                    $info['banner_img_url'] = $banner_img_url;

                    /*删除文件*/
                    $banner_img_url_path = '..'.$kitchen_video['banner_img_url'];
                    if(file_exists($banner_img_url_path)){
                        unlink($banner_img_url_path);
                    }
                }
            }

            $info['title'] = $title;
            $info['content'] = $content;
            $info['top'] = $top;

            /*更新时间*/
            $info['datetime'] = date('Y-m-d H:i:s');
            $info['time'] = time();

            $edit_wash_clean_kitchen_video = $db_wash_clean_kitchen->where("id='$id'")->setField($info);
            if($edit_wash_clean_kitchen_video){
                $this->redirect('Clean/kitchen_video');
            }else{
                $this->error('保存失败!');
            }
        }

        $this->meta_title = '厨房清洁-视频-编辑';//页面title信息
        $this->assign('title', '厨房清洁-视频-编辑');//页面标题
        $this->display();
    }

    /**
     * 厨房清洁-视频-删除
     */
    public function kitchen_video_del(){
        $db_wash_clean_kitchen = M('wash_clean_kitchen');//实例化厨房清洁信息表

        $id = I('get.id');
        $kitchen_video = $db_wash_clean_kitchen->where("id='$id'")->find();

        /*删除文件*/
        $video_url_path = '..'.$kitchen_video['video_url'];
        if(file_exists($video_url_path)){
            unlink($video_url_path);
        }

        /*删除文件*/
        $banner_img_url_path = '..'.$kitchen_video['banner_img_url'];
        if(file_exists($banner_img_url_path)){
            unlink($banner_img_url_path);
        }

        /*删除图文混排图片*/
        $this->del_images_path($kitchen_video['content'],2);

        $del_wash_clean_kitchen_video = $db_wash_clean_kitchen->where("id='$id'")->delete();
        if($del_wash_clean_kitchen_video){
            $this->success('删除成功!');
        }else{
            $this->error('删除失败!');
        }
    }

    /**
     * 厨房清洁-视频-详情
     */
    public function kitchen_video_detail(){
        $db_wash_clean_kitchen = M('wash_clean_kitchen');//实例化厨房清洁信息表

        $id = I('get.id');
        $kitchen_video = $db_wash_clean_kitchen->where("id='$id'")->find();
        $this->assign('kitchen_video', $kitchen_video);

        $this->meta_title = '厨房清洁-视频-详情';//页面title信息
        $this->assign('title', '厨房清洁-视频-详情');//页面标题
        $this->display();
    }

    /**
     * 卧室清洁-图文
     */
    public function bedroom_word(){
        $db_wash_clean_bedroom = M('wash_clean_bedroom');//实例化卧室清洁信息表

        $type = 1;//1图文 2视频
        $wash_clean_bedroom = $db_wash_clean_bedroom->where("type='$type'")->order('top DESC,search_times DESC,id DESC')->field('id,title,banner_img_url,search_times,datetime,top')->select();
        $arr = $wash_clean_bedroom;

        /* 数组分页 */
        import("ORG.Util.Page"); //导入分页类
        $count = count($arr);//获取数组长度
        $Page = new \Think\Page($count, 10);//设置每页显示条数
        $Page->rollPage = 5;//中间显示页数(如果不配置将隐藏首尾页)
        $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        $show = $Page->show();// 分页显示输出
        $list = array_slice($arr, $Page->firstRow, $Page->listRows);
        $this->assign('list', $list);// 赋值数据集
        $this->assign('page', $show);// 赋值分页输出

        $this->meta_title = '卧室清洁-图文';//页面title信息
        $this->assign('title', '卧室清洁-图文');//页面标题
        $this->display();
    }

    /**
     * 卧室清洁-图文-新增
     */
    public function bedroom_word_add(){
        $db_wash_clean_bedroom = M('wash_clean_bedroom');//实例化卧室清洁信息表

        if(IS_POST){
            $title = I('post.title');
            $content = I('post.content');
            $top = I('post.top');

            /*文件上传*/
            $savename = time().'_'.mt_rand(1000000,9999999);
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize = 2048000;// 设置附件上传大小 2M=2048000
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
            $upload->savePath = './Clean/bedroom_word/picture/'; // 设置附件上传（子）目录
            $upload->saveName = $savename; // 上传文件的文件名
            //$upload->saveExt = 'jpg'; // 上传文件的保存后缀，不设置的话使用原文件后缀
            $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
            $upload->replace = true; // true会存在同名文件将覆盖
            // 上传文件
            $upload_info = $upload->upload();
            if (!$upload_info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }else{
                $banner_img_url = "/wash_helper/Uploads/Clean/bedroom_word/picture/".$upload_info['file']['savename'];
                $info['banner_img_url'] = $banner_img_url;

                $info['title'] = $title;
                $info['content'] = $content;
                $info['top'] = $top;
                $info['type'] = 1; //1图文 2视频
                $info['search_times'] = 0; //搜索次数

                /*生成cid*/
                $cid = create_cid('wash_clean_bedroom');
                $info['cid'] = $cid;

                /*更新时间*/
                $info['datetime'] = date('Y-m-d H:i:s');
                $info['time'] = time();

                $add_wash_clean_bedroom_word = $db_wash_clean_bedroom->data($info)->add();
                if($add_wash_clean_bedroom_word){
                    $this->redirect('Clean/bedroom_word');
                }else{
                    $this->error('保存失败!');
                }
            }
        }

        $this->meta_title = '卧室清洁-图文-新增';//页面title信息
        $this->assign('title', '卧室清洁-图文-新增');//页面标题
        $this->display();
    }

    /**
     * 卧室清洁-图文-编辑
     */
    public function bedroom_word_edit(){
        $db_wash_clean_bedroom = M('wash_clean_bedroom');//实例化卧室清洁信息表

        $id = I('get.id');
        $bedroom_word = $db_wash_clean_bedroom->where("id='$id'")->find();
        $this->assign('bedroom_word', $bedroom_word);

        if(IS_POST){
            $title = I('post.title');
            $content = I('post.content');
            $top = I('post.top');

            //判断是否有文件上传
            if($_FILES["file"]["tmp_name"]){
                /*文件上传*/
                $savename = time().'_'.mt_rand(1000000,9999999);
                $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize = 2048000;// 设置附件上传大小 2M=2048000
                $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
                $upload->savePath = './Clean/bedroom_word/picture/'; // 设置附件上传（子）目录
                $upload->saveName = $savename; // 上传文件的文件名
                //$upload->saveExt = 'jpg'; // 上传文件的保存后缀，不设置的话使用原文件后缀
                $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
                $upload->replace = true; // true会存在同名文件将覆盖
                // 上传文件
                $upload_info = $upload->upload();
                if (!$upload_info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{
                    $banner_img_url = "/wash_helper/Uploads/Clean/bedroom_word/picture/".$upload_info['file']['savename'];
                    $info['banner_img_url'] = $banner_img_url;

                    /*删除文件*/
                    $banner_img_url_path = '..'.$bedroom_word['banner_img_url'];
                    if(file_exists($banner_img_url_path)){
                        unlink($banner_img_url_path);
                    }
                }
            }

            $info['title'] = $title;
            $info['content'] = $content;
            $info['top'] = $top;

            /*更新时间*/
            $info['datetime'] = date('Y-m-d H:i:s');
            $info['time'] = time();

            $edit_wash_clean_bedroom_word = $db_wash_clean_bedroom->where("id='$id'")->setField($info);
            if($edit_wash_clean_bedroom_word){
                $this->redirect('Clean/bedroom_word');
            }else{
                $this->error('保存失败!');
            }
        }

        $this->meta_title = '卧室清洁-图文-编辑';//页面title信息
        $this->assign('title', '卧室清洁-图文-编辑');//页面标题
        $this->display();
    }

    /**
     * 卧室清洁-图文-删除
     */
    public function bedroom_word_del(){
        $db_wash_clean_bedroom = M('wash_clean_bedroom');//实例化卧室清洁信息表

        $id = I('get.id');
        $bedroom_word = $db_wash_clean_bedroom->where("id='$id'")->find();

        /*删除文件*/
        $banner_img_url_path = '..'.$bedroom_word['banner_img_url'];
        if(file_exists($banner_img_url_path)){
            unlink($banner_img_url_path);
        }

        /*删除图文混排图片*/
        $this->del_images_path($bedroom_word['content'],2);

        $del_wash_clean_bedroom_word = $db_wash_clean_bedroom->where("id='$id'")->delete();
        if($del_wash_clean_bedroom_word){
            $this->success('删除成功!');
        }else{
            $this->error('删除失败!');
        }
    }

    /**
     * 卧室清洁-图文-详情
     */
    public function bedroom_word_detail(){
        $db_wash_clean_bedroom = M('wash_clean_bedroom');//实例化卧室清洁信息表

        $id = I('get.id');
        $bedroom_word = $db_wash_clean_bedroom->where("id='$id'")->find();
        $this->assign('bedroom_word', $bedroom_word);

        $this->meta_title = '卧室清洁-图文-详情';//页面title信息
        $this->assign('title', '卧室清洁-图文-详情');//页面标题
        $this->display();
    }

    /**
     * 卧室清洁-视频
     */
    public function bedroom_video(){
        $db_wash_clean_bedroom = M('wash_clean_bedroom');//实例化卧室清洁信息表

        $type = 2;//1图文 2视频
        $wash_clean_bedroom_video = $db_wash_clean_bedroom->where("type='$type'")->order('top DESC,search_times DESC,id DESC')->field('id,title,banner_img_url,video_url,search_times,datetime,top')->select();
        $arr = $wash_clean_bedroom_video;

        /* 数组分页 */
        import("ORG.Util.Page"); //导入分页类
        $count = count($arr);//获取数组长度
        $Page = new \Think\Page($count, 10);//设置每页显示条数
        $Page->rollPage = 5;//中间显示页数(如果不配置将隐藏首尾页)
        $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        $show = $Page->show();// 分页显示输出
        $list = array_slice($arr, $Page->firstRow, $Page->listRows);
        $this->assign('list', $list);// 赋值数据集
        $this->assign('page', $show);// 赋值分页输出

        $this->meta_title = '卧室清洁-视频';//页面title信息
        $this->assign('title', '卧室清洁-视频');//页面标题
        $this->display();
    }

    /**
     * 卧室清洁-视频-新增
     */
    public function bedroom_video_add(){
        $db_wash_clean_bedroom = M('wash_clean_bedroom');//实例化卧室清洁信息表

        if(IS_POST){
            $title = I('post.title');
            $content = I('post.content');
            $top = I('post.top');

            /*文件上传*/
            $videofile = array();
            $imagefile = array();
            $savename = time().'_'.mt_rand(1000000,9999999);
            $upload = new \Think\Upload();// 实例化上传类

            /*上传视频*/
            $videofile['video'] = $_FILES['video'];
            $upload->maxSize = 5120000;// 设置附件上传大小 5M=5120000
            $upload->exts = array('mp4', 'webm', 'ogg');// 设置附件上传类型
            $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
            $upload->savePath = './Clean/bedroom_video/video/'; // 设置附件上传（子）目录
            $upload->saveName = $savename; // 上传文件的文件名
            //$upload->saveExt = 'mp4'; // 上传文件的保存后缀，不设置的话使用原文件后缀
            $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
            $upload->replace = true; // true会存在同名文件将覆盖
            // 上传文件
            $upload_video_info = $upload->upload($videofile);
            if (!$upload_video_info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }

            /*上传图片*/
            $imagefile['picture'] = $_FILES['picture'];
            $upload->maxSize = 2048000;// 设置附件上传大小 2M=2048000
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
            $upload->savePath = './Clean/bedroom_video/picture/'; // 设置附件上传（子）目录
            $upload->saveName = $savename; // 上传文件的文件名
            //$upload->saveExt = 'jpg'; // 上传文件的保存后缀，不设置的话使用原文件后缀
            $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
            $upload->replace = true; // true会存在同名文件将覆盖
            // 上传文件
            $upload_picture_info = $upload->upload($imagefile);
            if (!$upload_picture_info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }

            $video_url = "/wash_helper/Uploads/Clean/bedroom_video/video/".$upload_video_info['video']['savename'];
            $info['video_url'] = $video_url;
            $banner_img_url = "/wash_helper/Uploads/Clean/bedroom_video/picture/".$upload_picture_info['picture']['savename'];
            $info['banner_img_url'] = $banner_img_url;

            $info['title'] = $title;
            $info['content'] = $content;
            $info['type'] = 2; //1图文 2视频
            $info['search_times'] = 0; //搜索次数
            $info['top'] = $top;

            /*生成cid*/
            $cid = create_cid('wash_clean_bedroom');
            $info['cid'] = $cid;

            /*更新时间*/
            $info['datetime'] = date('Y-m-d H:i:s');
            $info['time'] = time();

            $add_wash_clean_bedroom_video = $db_wash_clean_bedroom->data($info)->add();
            if($add_wash_clean_bedroom_video){
                $this->redirect('Clean/bedroom_video');
            }else{
                $this->error('保存失败!');
            }
        }

        $this->meta_title = '卧室清洁-视频-新增';//页面title信息
        $this->assign('title', '卧室清洁-视频-新增');//页面标题
        $this->display();
    }

    /**
     * 卧室清洁-视频-编辑
     */
    public function bedroom_video_edit(){
        $db_wash_clean_bedroom = M('wash_clean_bedroom');//实例化卧室清洁信息表

        $id = I('get.id');
        $bedroom_video = $db_wash_clean_bedroom->where("id='$id'")->find();
        $this->assign('bedroom_video', $bedroom_video);

        if(IS_POST){
            $title = I('post.title');
            $content = I('post.content');
            $top = I('post.top');

            //判断是否有视频上传
            if($_FILES["video"]["tmp_name"]) {
                $videofile = array();
                /*上传视频*/
                $savename = time().'_'.mt_rand(1000000,9999999);
                $upload = new \Think\Upload();// 实例化上传类

                $videofile['video'] = $_FILES['video'];
                $upload->maxSize = 5120000;// 设置附件上传大小 5M=5120000
                $upload->exts = array('mp4', 'webm', 'ogg');// 设置附件上传类型
                $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
                $upload->savePath = './Clean/bedroom_video/video/'; // 设置附件上传（子）目录
                $upload->saveName = $savename; // 上传文件的文件名
                //$upload->saveExt = 'mp4'; // 上传文件的保存后缀，不设置的话使用原文件后缀
                $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
                $upload->replace = true; // true会存在同名文件将覆盖
                // 上传文件
                $upload_video_info = $upload->upload($videofile);
                if (!$upload_video_info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{
                    $video_url = "/wash_helper/Uploads/Clean/bedroom_video/video/".$upload_video_info['video']['savename'];
                    $info['video_url'] = $video_url;

                    /*删除文件*/
                    $video_url_path = '..'.$bedroom_video['video_url'];
                    if(file_exists($video_url_path)){
                        unlink($video_url_path);
                    }
                }
            }

            //判断是否有图片上传
            if($_FILES["picture"]["tmp_name"]) {
                $imagefile = array();
                /*上传图片*/
                $savename = time().'_'.mt_rand(1000000,9999999);
                $upload = new \Think\Upload();// 实例化上传类

                $imagefile['picture'] = $_FILES['picture'];
                $upload->maxSize = 2048000;// 设置附件上传大小 2M=2048000
                $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
                $upload->savePath = './Clean/bedroom_video/picture/'; // 设置附件上传（子）目录
                $upload->saveName = $savename; // 上传文件的文件名
                //$upload->saveExt = 'jpg'; // 上传文件的保存后缀，不设置的话使用原文件后缀
                $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
                $upload->replace = true; // true会存在同名文件将覆盖
                // 上传文件
                $upload_picture_info = $upload->upload($imagefile);
                if (!$upload_picture_info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{
                    $banner_img_url = "/wash_helper/Uploads/Clean/bedroom_video/picture/".$upload_picture_info['picture']['savename'];
                    $info['banner_img_url'] = $banner_img_url;

                    /*删除文件*/
                    $banner_img_url_path = '..'.$bedroom_video['banner_img_url'];
                    if(file_exists($banner_img_url_path)){
                        unlink($banner_img_url_path);
                    }
                }
            }

            $info['title'] = $title;
            $info['content'] = $content;
            $info['top'] = $top;

            /*更新时间*/
            $info['datetime'] = date('Y-m-d H:i:s');
            $info['time'] = time();

            $edit_wash_clean_bedroom_video = $db_wash_clean_bedroom->where("id='$id'")->setField($info);
            if($edit_wash_clean_bedroom_video){
                $this->redirect('Clean/bedroom_video');
            }else{
                $this->error('保存失败!');
            }
        }

        $this->meta_title = '卧室清洁-视频-编辑';//页面title信息
        $this->assign('title', '卧室清洁-视频-编辑');//页面标题
        $this->display();
    }

    /**
     * 卧室清洁-视频-删除
     */
    public function bedroom_video_del(){
        $db_wash_clean_bedroom = M('wash_clean_bedroom');//实例化卧室清洁信息表

        $id = I('get.id');
        $bedroom_video = $db_wash_clean_bedroom->where("id='$id'")->find();

        /*删除文件*/
        $video_url_path = '..'.$bedroom_video['video_url'];
        if(file_exists($video_url_path)){
            unlink($video_url_path);
        }

        /*删除文件*/
        $banner_img_url_path = '..'.$bedroom_video['banner_img_url'];
        if(file_exists($banner_img_url_path)){
            unlink($banner_img_url_path);
        }

        /*删除图文混排图片*/
        $this->del_images_path($bedroom_video['content'],2);

        $del_wash_clean_bedroom_video = $db_wash_clean_bedroom->where("id='$id'")->delete();
        if($del_wash_clean_bedroom_video){
            $this->success('删除成功!');
        }else{
            $this->error('删除失败!');
        }
    }

    /**
     * 卧室清洁-视频-详情
     */
    public function bedroom_video_detail(){
        $db_wash_clean_bedroom = M('wash_clean_bedroom');//实例化卧室清洁信息表

        $id = I('get.id');
        $bedroom_video = $db_wash_clean_bedroom->where("id='$id'")->find();
        $this->assign('bedroom_video', $bedroom_video);

        $this->meta_title = '卧室清洁-视频-详情';//页面title信息
        $this->assign('title', '卧室清洁-视频-详情');//页面标题
        $this->display();
    }

    /**
     * 卫浴清洁-图文
     */
    public function bathroom_word(){
        $db_wash_clean_bathroom = M('wash_clean_bathroom');//实例化卫浴清洁信息表

        $type = 1;//1图文 2视频
        $wash_clean_bathroom = $db_wash_clean_bathroom->where("type='$type'")->order('top DESC,search_times DESC,id DESC')->field('id,title,banner_img_url,search_times,datetime,top')->select();
        $arr = $wash_clean_bathroom;

        /* 数组分页 */
        import("ORG.Util.Page"); //导入分页类
        $count = count($arr);//获取数组长度
        $Page = new \Think\Page($count, 10);//设置每页显示条数
        $Page->rollPage = 5;//中间显示页数(如果不配置将隐藏首尾页)
        $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        $show = $Page->show();// 分页显示输出
        $list = array_slice($arr, $Page->firstRow, $Page->listRows);
        $this->assign('list', $list);// 赋值数据集
        $this->assign('page', $show);// 赋值分页输出

        $this->meta_title = '卫浴清洁-图文';//页面title信息
        $this->assign('title', '卫浴清洁-图文');//页面标题
        $this->display();
    }

    /**
     * 卫浴清洁-图文-新增
     */
    public function bathroom_word_add(){
        $db_wash_clean_bathroom = M('wash_clean_bathroom');//实例化卫浴清洁信息表

        if(IS_POST){
            $title = I('post.title');
            $content = I('post.content');
            $top = I('post.top');

            /*文件上传*/
            $savename = time().'_'.mt_rand(1000000,9999999);
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize = 2048000;// 设置附件上传大小 2M=2048000
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
            $upload->savePath = './Clean/bathroom_word/picture/'; // 设置附件上传（子）目录
            $upload->saveName = $savename; // 上传文件的文件名
            //$upload->saveExt = 'jpg'; // 上传文件的保存后缀，不设置的话使用原文件后缀
            $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
            $upload->replace = true; // true会存在同名文件将覆盖
            // 上传文件
            $upload_info = $upload->upload();
            if (!$upload_info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }else{
                $banner_img_url = "/wash_helper/Uploads/Clean/bathroom_word/picture/".$upload_info['file']['savename'];
                $info['banner_img_url'] = $banner_img_url;

                $info['title'] = $title;
                $info['content'] = $content;
                $info['top'] = $top;
                $info['type'] = 1; //1图文 2视频
                $info['search_times'] = 0; //搜索次数

                /*生成cid*/
                $cid = create_cid('wash_clean_bathroom');
                $info['cid'] = $cid;

                /*更新时间*/
                $info['datetime'] = date('Y-m-d H:i:s');
                $info['time'] = time();

                $add_wash_clean_bathroom_word = $db_wash_clean_bathroom->data($info)->add();
                if($add_wash_clean_bathroom_word){
                    $this->redirect('Clean/bathroom_word');
                }else{
                    $this->error('保存失败!');
                }
            }
        }

        $this->meta_title = '卫浴清洁-图文-新增';//页面title信息
        $this->assign('title', '卫浴清洁-图文-新增');//页面标题
        $this->display();
    }

    /**
     * 卫浴清洁-图文-编辑
     */
    public function bathroom_word_edit(){
        $db_wash_clean_bathroom = M('wash_clean_bathroom');//实例化卫浴清洁信息表

        $id = I('get.id');
        $bathroom_word = $db_wash_clean_bathroom->where("id='$id'")->find();
        $this->assign('bathroom_word', $bathroom_word);

        if(IS_POST){
            $title = I('post.title');
            $content = I('post.content');
            $top = I('post.top');

            //判断是否有文件上传
            if($_FILES["file"]["tmp_name"]){
                /*文件上传*/
                $savename = time().'_'.mt_rand(1000000,9999999);
                $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize = 2048000;// 设置附件上传大小 2M=2048000
                $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
                $upload->savePath = './Clean/bathroom_word/picture/'; // 设置附件上传（子）目录
                $upload->saveName = $savename; // 上传文件的文件名
                //$upload->saveExt = 'jpg'; // 上传文件的保存后缀，不设置的话使用原文件后缀
                $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
                $upload->replace = true; // true会存在同名文件将覆盖
                // 上传文件
                $upload_info = $upload->upload();
                if (!$upload_info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{
                    $banner_img_url = "/wash_helper/Uploads/Clean/bathroom_word/picture/".$upload_info['file']['savename'];
                    $info['banner_img_url'] = $banner_img_url;

                    /*删除文件*/
                    $banner_img_url_path = '..'.$bathroom_word['banner_img_url'];
                    if(file_exists($banner_img_url_path)){
                        unlink($banner_img_url_path);
                    }
                }
            }

            $info['title'] = $title;
            $info['content'] = $content;
            $info['top'] = $top;

            /*更新时间*/
            $info['datetime'] = date('Y-m-d H:i:s');
            $info['time'] = time();

            $edit_wash_clean_bathroom_word = $db_wash_clean_bathroom->where("id='$id'")->setField($info);
            if($edit_wash_clean_bathroom_word){
                $this->redirect('Clean/bathroom_word');
            }else{
                $this->error('保存失败!');
            }
        }

        $this->meta_title = '卫浴清洁-图文-编辑';//页面title信息
        $this->assign('title', '卫浴清洁-图文-编辑');//页面标题
        $this->display();
    }

    /**
     * 卫浴清洁-图文-删除
     */
    public function bathroom_word_del(){
        $db_wash_clean_bathroom = M('wash_clean_bathroom');//实例化卫浴清洁信息表

        $id = I('get.id');
        $bathroom_word = $db_wash_clean_bathroom->where("id='$id'")->find();

        /*删除文件*/
        $banner_img_url_path = '..'.$bathroom_word['banner_img_url'];
        if(file_exists($banner_img_url_path)){
            unlink($banner_img_url_path);
        }

        /*删除图文混排图片*/
        $this->del_images_path($bathroom_word['content'],2);

        $del_wash_clean_bathroom_word = $db_wash_clean_bathroom->where("id='$id'")->delete();
        if($del_wash_clean_bathroom_word){
            $this->success('删除成功!');
        }else{
            $this->error('删除失败!');
        }
    }

    /**
     * 卫浴清洁-图文-详情
     */
    public function bathroom_word_detail(){
        $db_wash_clean_bathroom = M('wash_clean_bathroom');//实例化卫浴清洁信息表

        $id = I('get.id');
        $bathroom_word = $db_wash_clean_bathroom->where("id='$id'")->find();
        $this->assign('bathroom_word', $bathroom_word);

        $this->meta_title = '卫浴清洁-图文-详情';//页面title信息
        $this->assign('title', '卫浴清洁-图文-详情');//页面标题
        $this->display();
    }

    /**
     * 卫浴清洁-视频
     */
    public function bathroom_video(){
        $db_wash_clean_bathroom = M('wash_clean_bathroom');//实例化卫浴清洁信息表

        $type = 2;//1图文 2视频
        $wash_clean_bathroom_video = $db_wash_clean_bathroom->where("type='$type'")->order('top DESC,search_times DESC,id DESC')->field('id,title,banner_img_url,video_url,search_times,datetime,top')->select();
        $arr = $wash_clean_bathroom_video;

        /* 数组分页 */
        import("ORG.Util.Page"); //导入分页类
        $count = count($arr);//获取数组长度
        $Page = new \Think\Page($count, 10);//设置每页显示条数
        $Page->rollPage = 5;//中间显示页数(如果不配置将隐藏首尾页)
        $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        $show = $Page->show();// 分页显示输出
        $list = array_slice($arr, $Page->firstRow, $Page->listRows);
        $this->assign('list', $list);// 赋值数据集
        $this->assign('page', $show);// 赋值分页输出

        $this->meta_title = '卫浴清洁-视频';//页面title信息
        $this->assign('title', '卫浴清洁-视频');//页面标题
        $this->display();
    }

    /**
     * 卫浴清洁-视频-新增
     */
    public function bathroom_video_add(){
        $db_wash_clean_bathroom = M('wash_clean_bathroom');//实例化卫浴清洁信息表

        if(IS_POST){
            $title = I('post.title');
            $content = I('post.content');
            $top = I('post.top');

            /*文件上传*/
            $videofile = array();
            $imagefile = array();
            $savename = time().'_'.mt_rand(1000000,9999999);
            $upload = new \Think\Upload();// 实例化上传类

            /*上传视频*/
            $videofile['video'] = $_FILES['video'];
            $upload->maxSize = 5120000;// 设置附件上传大小 5M=5120000
            $upload->exts = array('mp4', 'webm', 'ogg');// 设置附件上传类型
            $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
            $upload->savePath = './Clean/bathroom_video/video/'; // 设置附件上传（子）目录
            $upload->saveName = $savename; // 上传文件的文件名
            //$upload->saveExt = 'mp4'; // 上传文件的保存后缀，不设置的话使用原文件后缀
            $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
            $upload->replace = true; // true会存在同名文件将覆盖
            // 上传文件
            $upload_video_info = $upload->upload($videofile);
            if (!$upload_video_info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }

            /*上传图片*/
            $imagefile['picture'] = $_FILES['picture'];
            $upload->maxSize = 2048000;// 设置附件上传大小 2M=2048000
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
            $upload->savePath = './Clean/bathroom_video/picture/'; // 设置附件上传（子）目录
            $upload->saveName = $savename; // 上传文件的文件名
            //$upload->saveExt = 'jpg'; // 上传文件的保存后缀，不设置的话使用原文件后缀
            $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
            $upload->replace = true; // true会存在同名文件将覆盖
            // 上传文件
            $upload_picture_info = $upload->upload($imagefile);
            if (!$upload_picture_info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }

            $video_url = "/wash_helper/Uploads/Clean/bathroom_video/video/".$upload_video_info['video']['savename'];
            $info['video_url'] = $video_url;
            $banner_img_url = "/wash_helper/Uploads/Clean/bathroom_video/picture/".$upload_picture_info['picture']['savename'];
            $info['banner_img_url'] = $banner_img_url;

            $info['title'] = $title;
            $info['content'] = $content;
            $info['type'] = 2; //1图文 2视频
            $info['search_times'] = 0; //搜索次数
            $info['top'] = $top;

            /*生成cid*/
            $cid = create_cid('wash_clean_bathroom');
            $info['cid'] = $cid;

            /*更新时间*/
            $info['datetime'] = date('Y-m-d H:i:s');
            $info['time'] = time();

            $add_wash_clean_bathroom_video = $db_wash_clean_bathroom->data($info)->add();
            if($add_wash_clean_bathroom_video){
                $this->redirect('Clean/bathroom_video');
            }else{
                $this->error('保存失败!');
            }
        }

        $this->meta_title = '卫浴清洁-视频-新增';//页面title信息
        $this->assign('title', '卫浴清洁-视频-新增');//页面标题
        $this->display();
    }

    /**
     * 卫浴清洁-视频-编辑
     */
    public function bathroom_video_edit(){
        $db_wash_clean_bathroom = M('wash_clean_bathroom');//实例化卫浴清洁信息表

        $id = I('get.id');
        $bathroom_video = $db_wash_clean_bathroom->where("id='$id'")->find();
        $this->assign('bathroom_video', $bathroom_video);

        if(IS_POST){
            $title = I('post.title');
            $content = I('post.content');
            $top = I('post.top');

            //判断是否有视频上传
            if($_FILES["video"]["tmp_name"]) {
                $videofile = array();
                /*上传视频*/
                $savename = time().'_'.mt_rand(1000000,9999999);
                $upload = new \Think\Upload();// 实例化上传类

                $videofile['video'] = $_FILES['video'];
                $upload->maxSize = 5120000;// 设置附件上传大小 5M=5120000
                $upload->exts = array('mp4', 'webm', 'ogg');// 设置附件上传类型
                $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
                $upload->savePath = './Clean/bathroom_video/video/'; // 设置附件上传（子）目录
                $upload->saveName = $savename; // 上传文件的文件名
                //$upload->saveExt = 'mp4'; // 上传文件的保存后缀，不设置的话使用原文件后缀
                $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
                $upload->replace = true; // true会存在同名文件将覆盖
                // 上传文件
                $upload_video_info = $upload->upload($videofile);
                if (!$upload_video_info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{
                    $video_url = "/wash_helper/Uploads/Clean/bathroom_video/video/".$upload_video_info['video']['savename'];
                    $info['video_url'] = $video_url;

                    /*删除文件*/
                    $video_url_path = '..'.$bathroom_video['video_url'];
                    if(file_exists($video_url_path)){
                        unlink($video_url_path);
                    }
                }
            }

            //判断是否有图片上传
            if($_FILES["picture"]["tmp_name"]) {
                $imagefile = array();
                /*上传图片*/
                $savename = time().'_'.mt_rand(1000000,9999999);
                $upload = new \Think\Upload();// 实例化上传类

                $imagefile['picture'] = $_FILES['picture'];
                $upload->maxSize = 2048000;// 设置附件上传大小 2M=2048000
                $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath = '../../Uploads/'; // 设置附件上传根目录
                $upload->savePath = './Clean/bathroom_video/picture/'; // 设置附件上传（子）目录
                $upload->saveName = $savename; // 上传文件的文件名
                //$upload->saveExt = 'jpg'; // 上传文件的保存后缀，不设置的话使用原文件后缀
                $upload->autoSub = false; // true会自动在目录文件夹下生成以日期命名的子文件夹
                $upload->replace = true; // true会存在同名文件将覆盖
                // 上传文件
                $upload_picture_info = $upload->upload($imagefile);
                if (!$upload_picture_info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{
                    $banner_img_url = "/wash_helper/Uploads/Clean/bathroom_video/picture/".$upload_picture_info['picture']['savename'];
                    $info['banner_img_url'] = $banner_img_url;

                    /*删除文件*/
                    $banner_img_url_path = '..'.$bathroom_video['banner_img_url'];
                    if(file_exists($banner_img_url_path)){
                        unlink($banner_img_url_path);
                    }
                }
            }

            $info['title'] = $title;
            $info['content'] = $content;
            $info['top'] = $top;

            /*更新时间*/
            $info['datetime'] = date('Y-m-d H:i:s');
            $info['time'] = time();

            $edit_wash_clean_bathroom_video = $db_wash_clean_bathroom->where("id='$id'")->setField($info);
            if($edit_wash_clean_bathroom_video){
                $this->redirect('Clean/bathroom_video');
            }else{
                $this->error('保存失败!');
            }
        }

        $this->meta_title = '卫浴清洁-视频-编辑';//页面title信息
        $this->assign('title', '卫浴清洁-视频-编辑');//页面标题
        $this->display();
    }

    /**
     * 卫浴清洁-视频-删除
     */
    public function bathroom_video_del(){
        $db_wash_clean_bathroom = M('wash_clean_bathroom');//实例化卫浴清洁信息表

        $id = I('get.id');
        $bathroom_video = $db_wash_clean_bathroom->where("id='$id'")->find();

        /*删除文件*/
        $video_url_path = '..'.$bathroom_video['video_url'];
        if(file_exists($video_url_path)){
            unlink($video_url_path);
        }

        /*删除文件*/
        $banner_img_url_path = '..'.$bathroom_video['banner_img_url'];
        if(file_exists($banner_img_url_path)){
            unlink($banner_img_url_path);
        }

        /*删除图文混排图片*/
        $this->del_images_path($bathroom_video['content'],2);

        $del_wash_clean_bathroom_video = $db_wash_clean_bathroom->where("id='$id'")->delete();
        if($del_wash_clean_bathroom_video){
            $this->success('删除成功!');
        }else{
            $this->error('删除失败!');
        }
    }

    /**
     * 卫浴清洁-视频-详情
     */
    public function bathroom_video_detail(){
        $db_wash_clean_bathroom = M('wash_clean_bathroom');//实例化卫浴清洁信息表

        $id = I('get.id');
        $bathroom_video = $db_wash_clean_bathroom->where("id='$id'")->find();
        $this->assign('bathroom_video', $bathroom_video);

        $this->meta_title = '卫浴清洁-视频-详情';//页面title信息
        $this->assign('title', '卫浴清洁-视频-详情');//页面标题
        $this->display();
    }

    /**
     * 删除图文混排图片
     * str  $str    要提去的字符串
     * int  $type   1提取图片 2提取src和href
     */
    public function del_images_path($str,$type=1){
        if($type == 1){
            preg_match('/<img.+src=\"?(.+\.(jpg|gif|jpeg|png))\"?.+>/i',$str,$match);
            if($match[1]){
                foreach($match[1] as $v){
                    $images_path = '..'.$v;
                    if(file_exists($images_path)){
                        unlink($images_path);
                    }
                }
            }
        }
        if($type == 2){
            preg_match_all('/(src|href)=\"?(.+\.(jpg|gif|jpeg|png))\"/i',$str,$match);
            if($match[2]){
                foreach($match[2] as $v){
                    $images_path = '..'.$v;
                    if(file_exists($images_path)){
                        unlink($images_path);
                    }
                }
            }
        }
    }
}
